package service

import (
	sqlc "bgs/db/sqlc"
	"context"
)

type UpsertBrandDistributeProductParam struct {
	BrandID     int64
	ProductID   int64
	PercentSale int32
	PercentOff  int32
}

// UpsertBrandDistributeProduct
func (s *BrandServiceImp) UpsertBrandDistributeProduct(ctx context.Context, q *sqlc.Queries, ptr *UpsertBrandDistributeProductParam) (rptr *sqlc.BrandDistributeProduct, err error) {
	entity, err := q.UpsertBrandDistributeProduct(ctx, sqlc.UpsertBrandDistributeProductParams{
		BrandID:     ptr.BrandID,
		ProductID:   ptr.ProductID,
		PercentSale: ptr.PercentSale,
		PercentOff:  ptr.PercentOff,
	})
	if err != nil {
		return
	}
	rptr = &entity
	return
}

// BatchUpsertBrandDistributeProducts
func (s *BrandServiceImp) BatchUpsertBrandDistributeProducts(ctx context.Context, q *sqlc.Queries, ptr *UpsertBrandDistributeProductParam) (err error) {
	cnt, err := q.BatchUpsertBrandDistributeProducts(ctx, sqlc.BatchUpsertBrandDistributeProductsParams{
		BrandID:     ptr.BrandID,
		PercentSale: ptr.PercentSale,
		PercentOff:  ptr.PercentOff,
	})
	if err != nil {
		return
	}
	s.slog.Infof("BatchUpsertBrandDistributeProducts cnt(%d) ok", cnt)
	return
}
